package com.wang.myapplication.network;

import com.wang.myapplication.network.bean.LoginResponse;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.http.GET;
import retrofit2.http.Query;

/**
 * Created by xhwang on 2018/3/20.
 */

public class Network {

    //http://112.74.195.215:100/VHKM/wsuser.asmx/Login?uid=wxq&pwd=wxq
    private static String baseUrl = "http://112.74.195.215:100/VHKM/wsuser.asmx/";
    private static Retrofit retrofit;

    public static Retrofit initRetrofit() {
        //声明日志类
        HttpLoggingInterceptor httpLoggingInterceptor = new HttpLoggingInterceptor();
        //设定日志级别
        httpLoggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        //自定义OkHttpClient
        OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
        //添加拦截器
        okHttpClient.addInterceptor(httpLoggingInterceptor);


        //创建并指定自定义的OkHttpClient
        retrofit = new Retrofit.Builder()
                .baseUrl(baseUrl)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .client(okHttpClient.build())//此行为了log
                .build();
        return retrofit;
    }


    public interface LoginServices {
        @GET("Login")
//        Call<ResponseBody> loginRequest(@Query("uid") String uid, @Query("pwd") String pwd);
        Call<LoginResponse> loginRequest(@Query("uid") String uid, @Query("pwd") String pwd);
    }

}
